<template>
  <div class="audit-trad-price-change-view">

    <el-form :inline="true" label-width="110px" label-position="right" size="small">

      <el-row>

        <el-col :span="8">
          <el-form-item label="流程编号：">
            {{ detailData.processNo }}
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="创建时间：">
            {{ dateFormat('yyyy-mm-dd',detailData.startTime) }}
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="创建人：">
            {{ detailData.initiator }}
          </el-form-item>
        </el-col>

      </el-row>

    </el-form>

    <item-title :title="datas.Old?.agentType == 'agent' ? '代理商信息' : '兼职信息'" />

    <el-form :inline="true" label-width="110px" label-position="right" size="small">

      <el-row>

        <el-col :span="8">

          <el-form-item
            v-if="datas.Old?.agentType == 'agent'"
            label="代理名称："
          >
            {{ datas.Old?.agentName }}
          </el-form-item>
          <el-form-item
            v-else
            label="代理名称："
          >
            {{ datas.Old?.userName }}
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="招商要素编号：">
            {{ datas.Old?.agentProductNumber }}
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="产品信息：">
            {{ getProductName(datas.Old) }}
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="代理属性：">
            {{ getLabel(datas.Old?.agentType , datas.Old?.agentAttribute) }}
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="代理地区：">
            <area-list-view :areas="datas.Old?.region" />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="负责营销职员：">
            {{ datas.Old?.headName }}
          </el-form-item>
        </el-col>

      </el-row>

    </el-form>

    <el-form label-width="110px" label-position="right" size="small">

      <el-form-item label="交易价：">

        <div class="flow-status-color">
          {{ datas.Old?.tradePrice }}元
          <span v-if="datas.Old?.sellUnit">/{{ getLabel("sell_unit", datas.Old?.sellUnit) }}</span>
          --> {{ datas.newTradePrice }}元
          <span v-if="datas.Old?.sellUnit">/{{ getLabel("sell_unit", datas.Old?.sellUnit) }}</span>
        </div>
      </el-form-item>

      <el-form-item label="变更原因：">
        {{ datas.reason }}
      </el-form-item>

    </el-form>

    <template v-if="tableData.length">
      <div style="margin: 20px 0">同时更新以下关联交易终端中的交易价</div>

      <el-table
        :data="tableData"
        border
      >
        <el-table-column
          header-align="center"
          align="center"
          label="终端名称"
          prop="terminalName"
        />
        <el-table-column
          header-align="center"
          align="center"
          label="终端类型"
        >
          <template #default="scope">
            {{ getLabel('app_mode',scope.row.terminalType) }}
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          label="终端所在地区"
        >
          <template #default="scope">
            {{ scope.row.provinceName }}/{{ scope.row.cityName }}/{{ scope.row.areaName }}
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          label="终端价(元)"
        >
          <template #default="scope">
            ¥{{ scope.row.terminalPrice }}
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          label="当前交易价(元)"
        >
          <template #default="scope">
            ¥{{ scope.row.tradePrice }}
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          label="更新后交易价(元)"
        >
          <template #default="scope">
            ¥{{ datas.newTradePrice }}
          </template>
        </el-table-column>

      </el-table>
    </template>

  </div>
</template>

<script>
// 代理产品交易价变更审批
import {defineComponent, reactive, toRefs, watch} from 'vue'

export default defineComponent({
  name: 'TradPriceChange',
  props: {
    detailData: {
      type: Object,
      default: {},
    },
  },
  setup(props) {
    var data = reactive({
      datas: {},
      tableData: [],
      type: 'agent',
    })

    watch(
      () => props.detailData,
      (newval, oldval) => {
        if (newval && newval.data) {
          console.log(newval)
          console.log(newval.data)
          if (
            newval.processDefinitionKey == 'agentPersonProductCreate' ||
            newval.processDefinitionKey == 'agentPersonProductChangePrice' ||
            newval.processDefinitionKey == 'agentPersonProductBan'
          ) {
            data.type = 'agent_person'
          }
          data.datas = newval.data
          data.tableData = newval.data.Standards
        }
      },
      { immediate: true, deep: true }
    )

    return {
      ...toRefs(data),
    }
  },
})
</script>

<style scoped>
</style>
